package org.mathcloud.math.io.mml.content.generic;

import org.jdom.Element;
import org.jdom.Namespace;
import org.mathcloud.math.io.mml.content.common.ElementTranslator;


public abstract class GenericElementTranslator implements
		ElementTranslator
{
	
	public GenericElementTranslator()
	{
		requestElement = null;
		resultElement = null;
	}
	
	public GenericElementTranslator(String mmlTagName)
	{
		this.tagName = mmlTagName.toLowerCase();
		requestElement = null;
		resultElement = null;
	}
	
	@Override
	public void translate()
	{
		/* before getting in deep with processing 
		 * validation against XML Schema should be done
		 * We use are own XML Schema based on W3 XML Schema for Content MathML
		 * which provides more clear understanding of content  
		*/
	}

	@Override
	public Element getResultElement()
	{
		return resultElement;
	}
  
	public void setRequestElement(Element in)
	{
		requestElement = in;
	}
	
	
	public Element getCErrorElement(String message)
	{
		Element out = new Element("cerror", Namespace.getNamespace(prefix,namespaceURI));
		Element csymbol = new Element("csymbol",out.getNamespace());
		csymbol.setAttribute("cd", "error");
		csymbol.addContent(message);
		out.addContent(csymbol);
		Element t = (Element)requestElement.clone();
		out.addContent(t);
		return out;
	}
	
	public String getPrefix()
	{
		return prefix;
	}

	public void setPrefix(String prefix)
	{
		this.prefix = prefix;
	}


	public void setXMLSchemaLocation(String arg0)
	{
		xmlSchemaLocation = arg0;
	}
	
	
	public static String namespaceURI = "http://www.w3.org/1998/Math/MathML";
	public String prefix = "mml";
	
	public String xmlSchemaLocation;
   
  protected Element requestElement;
  protected Element resultElement;
  
  protected String tagName;
}
